<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: Broadcast
  
    &mdash; Documentation by YARD 0.7.3
  
</title>

  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />

  <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '';
  if (relpath != '') relpath += '/';
</script>

  <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="js/app.js"></script>


  </head>
  <body>
    <script type="text/javascript" charset="utf-8">
      if (window.top.frames.main) document.body.className = 'frames';
    </script>
    
    <div id="header">
      <div id="menu">
  
    <a href="_index.html">Index (B)</a> &raquo; 
    
    
    <span class="title">Broadcast</span>
  
  
  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a id="class_list_link" href="#">Class List</a>
  
    <a id="method_list_link" href="#">Method List</a>
  
    <a id="file_list_link" href="#">File List</a>
  
</div>
      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Class: Broadcast
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">ActiveRecord::Base</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">ActiveRecord::Base</li>
          
            <li class="next">Broadcast</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">app/models/broadcast.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>
ELMO - Secure, robust, and versatile data collection. Copyright 2011 The
Carter Center
</p>
<p>
ELMO is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
</p>
<p>
ELMO is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
</p>
<p>
You should have received a copy of the GNU General Public License along
with ELMO. If not, see &lt;http://www.gnu.org/licenses/&gt;.
</p>


  </div>
</div>
<div class="tags">
  

</div>

  


  

  
    <h2>
      Class Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#default_eager-class_method" title="default_eager (class method)">+ (Object) <strong>default_eager</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#medium_select_options-class_method" title="medium_select_options (class method)">+ (Object) <strong>medium_select_options</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#sorted-class_method" title="sorted (class method)">+ (Object) <strong>sorted</strong>(params) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
    </ul>
  
    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#add_send_error-instance_method" title="#add_send_error (instance method)">- (Object) <strong>add_send_error</strong>(msg) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#by_both%3F-instance_method" title="#by_both? (instance method)">- (Boolean) <strong>by_both?</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#by_email%3F-instance_method" title="#by_email? (instance method)">- (Boolean) <strong>by_email?</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#by_sms%3F-instance_method" title="#by_sms? (instance method)">- (Boolean) <strong>by_sms?</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#deliver-instance_method" title="#deliver (instance method)">- (Object) <strong>deliver</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#recipient_ids-instance_method" title="#recipient_ids (instance method)">- (Object) <strong>recipient_ids</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#recipient_ids%3D-instance_method" title="#recipient_ids= (instance method)">- (Object) <strong>recipient_ids=</strong>(ids) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#sort_recipients-instance_method" title="#sort_recipients (instance method)">- (Object) <strong>sort_recipients</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
    </ul>
  


  

  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>
    
    
      <div class="method_details first">
  <p class="signature first" id="default_eager-class_method">
  
    + (<tt>Object</tt>) <strong>default_eager</strong> 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


34
35
36</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 34</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='default_eager identifier id'>default_eager</span>
  <span class='lbrack token'>[</span><span class='symbol val'>:recipients</span><span class='rbrack token'>]</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="medium_select_options-class_method">
  
    + (<tt>Object</tt>) <strong>medium_select_options</strong> 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


38
39
40
41
42</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 38</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='medium_select_options identifier id'>medium_select_options</span>
  <span class='lbrack token'>[</span><span class='lbrack token'>[</span><span class='string val'>&quot;SMS preferred (email if no mobile phone)&quot;</span><span class='comma token'>,</span> <span class='string val'>&quot;sms&quot;</span><span class='rbrack token'>]</span><span class='comma token'>,</span>
   <span class='lbrack token'>[</span><span class='string val'>&quot;Email only&quot;</span><span class='comma token'>,</span> <span class='string val'>&quot;email&quot;</span><span class='rbrack token'>]</span><span class='comma token'>,</span>
   <span class='lbrack token'>[</span><span class='string val'>&quot;Both SMS and email&quot;</span><span class='comma token'>,</span> <span class='string val'>&quot;both&quot;</span><span class='rbrack token'>]</span><span class='rbrack token'>]</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="sorted-class_method">
  
    + (<tt>Object</tt>) <strong>sorted</strong>(params) 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


29
30
31
32</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 29</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='sorted identifier id'>sorted</span><span class='lparen token'>(</span><span class='params identifier id'>params</span><span class='rparen token'>)</span>
  <span class='params identifier id'>params</span><span class='dot token'>.</span><span class='merge! fid id'>merge!</span><span class='lparen token'>(</span><span class='symbol val'>:order</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;created_at desc&quot;</span><span class='rparen token'>)</span>
  <span class='paginate identifier id'>paginate</span><span class='lparen token'>(</span><span class='symbol val'>:all</span><span class='comma token'>,</span> <span class='params identifier id'>params</span><span class='rparen token'>)</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>
    
    
      <div class="method_details first">
  <p class="signature first" id="add_send_error-instance_method">
  
    - (<tt>Object</tt>) <strong>add_send_error</strong>(msg) 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


77
78
79</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 77</span>

<span class='def def kw'>def</span> <span class='add_send_error identifier id'>add_send_error</span><span class='lparen token'>(</span><span class='msg identifier id'>msg</span><span class='rparen token'>)</span>
  <span class='self self kw'>self</span><span class='dot token'>.</span><span class='send_errors identifier id'>send_errors</span> <span class='assign token'>=</span> <span class='lparen token'>(</span><span class='send_errors identifier id'>send_errors</span><span class='dot token'>.</span><span class='nil? fid id'>nil?</span> <span class='integer val'>? </span><span class='string val'>&quot;&quot;</span> <span class='colon op'>:</span> <span class='send_errors identifier id'>send_errors</span><span class='rparen token'>)</span> <span class='plus op'>+</span> <span class='msg identifier id'>msg</span> <span class='plus op'>+</span> <span class='string val'>&quot;\n&quot;</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="by_both?-instance_method">
  
    - (<tt>Boolean</tt>) <strong>by_both?</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    

  </div>
</div>
<div class="tags">
  
<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Boolean</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


52</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 52</span>

<span class='def def kw'>def</span> <span class='by_both? fid id'>by_both?</span><span class='semicolon token'>;</span> <span class='medium identifier id'>medium</span> <span class='eq op'>==</span> <span class='string val'>&quot;both&quot;</span> <span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="by_email?-instance_method">
  
    - (<tt>Boolean</tt>) <strong>by_email?</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    

  </div>
</div>
<div class="tags">
  
<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Boolean</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


51</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 51</span>

<span class='def def kw'>def</span> <span class='by_email? fid id'>by_email?</span><span class='semicolon token'>;</span> <span class='medium identifier id'>medium</span> <span class='eq op'>==</span> <span class='string val'>&quot;email&quot;</span> <span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="by_sms?-instance_method">
  
    - (<tt>Boolean</tt>) <strong>by_sms?</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    

  </div>
</div>
<div class="tags">
  
<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Boolean</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


50</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 50</span>

<span class='def def kw'>def</span> <span class='by_sms? fid id'>by_sms?</span><span class='semicolon token'>;</span> <span class='medium identifier id'>medium</span> <span class='eq op'>==</span> <span class='string val'>&quot;sms&quot;</span> <span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="deliver-instance_method">
  
    - (<tt>Object</tt>) <strong>deliver</strong> 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 54</span>

<span class='def def kw'>def</span> <span class='deliver identifier id'>deliver</span>
  <span class='comment val'># sort recipients into email and sms</span>
  <span class='smsees identifier id'>smsees</span><span class='comma token'>,</span> <span class='emailees identifier id'>emailees</span> <span class='assign token'>=</span> <span class='sort_recipients identifier id'>sort_recipients</span>
  <span class='comment val'># no sms recipients if email only</span>
  <span class='smsees identifier id'>smsees</span> <span class='assign token'>=</span> <span class='lbrack token'>[</span><span class='rbrack token'>]</span> <span class='if if_mod kw'>if</span> <span class='by_email? fid id'>by_email?</span>
  <span class='comment val'># everyone gets an email if email or both</span>
  <span class='emailees identifier id'>emailees</span> <span class='assign token'>=</span> <span class='recipients identifier id'>recipients</span> <span class='unless unless_mod kw'>unless</span> <span class='by_sms? fid id'>by_sms?</span>
  <span class='comment val'># send emails</span>
  <span class='begin begin kw'>begin</span>
    <span class='BroadcastMailer constant id'>BroadcastMailer</span><span class='dot token'>.</span><span class='broadcast identifier id'>broadcast</span><span class='lparen token'>(</span><span class='emailees identifier id'>emailees</span><span class='comma token'>,</span> <span class='subject identifier id'>subject</span><span class='comma token'>,</span> <span class='body identifier id'>body</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='deliver identifier id'>deliver</span> <span class='unless unless_mod kw'>unless</span> <span class='emailees identifier id'>emailees</span><span class='dot token'>.</span><span class='empty? fid id'>empty?</span>
  <span class='rescue rescue kw'>rescue</span>
    <span class='add_send_error identifier id'>add_send_error</span><span class='lparen token'>(</span><span class='dstring node'>&quot;Email Error: #{$!}&quot;</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
  <span class='comment val'># send smses</span>
  <span class='begin begin kw'>begin</span>
    <span class='Smser constant id'>Smser</span><span class='dot token'>.</span><span class='deliver identifier id'>deliver</span><span class='lparen token'>(</span><span class='smsees identifier id'>smsees</span><span class='comma token'>,</span> <span class='dstring node'>&quot;#{configatron.broadcast_tag} #{body}&quot;</span><span class='rparen token'>)</span> <span class='unless unless_mod kw'>unless</span> <span class='smsees identifier id'>smsees</span><span class='dot token'>.</span><span class='empty? fid id'>empty?</span>
  <span class='rescue rescue kw'>rescue</span>
    <span class='comment val'># one error per line</span>
    <span class='$! gvar id'>$!</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span><span class='dot token'>.</span><span class='split identifier id'>split</span><span class='lparen token'>(</span><span class='string val'>&quot;\n&quot;</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='each identifier id'>each</span><span class='lbrace token'>{</span><span class='bitor op'>|</span><span class='e identifier id'>e</span><span class='bitor op'>|</span> <span class='add_send_error identifier id'>add_send_error</span><span class='lparen token'>(</span><span class='dstring node'>&quot;SMS Error: #{e}&quot;</span><span class='rparen token'>)</span><span class='rbrace token'>}</span>
  <span class='end end kw'>end</span>
  <span class='return return kw'>return</span> <span class='true true kw'>true</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="recipient_ids-instance_method">
  
    - (<tt>Object</tt>) <strong>recipient_ids</strong> 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


44
45
46</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 44</span>

<span class='def def kw'>def</span> <span class='recipient_ids identifier id'>recipient_ids</span>
  <span class='recipients identifier id'>recipients</span><span class='dot token'>.</span><span class='collect identifier id'>collect</span><span class='lbrace token'>{</span><span class='bitor op'>|</span><span class='r identifier id'>r</span><span class='bitor op'>|</span> <span class='r identifier id'>r</span><span class='dot token'>.</span><span class='id identifier id'>id</span><span class='rbrace token'>}</span><span class='dot token'>.</span><span class='join identifier id'>join</span><span class='lparen token'>(</span><span class='string val'>&quot;,&quot;</span><span class='rparen token'>)</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="recipient_ids=-instance_method">
  
    - (<tt>Object</tt>) <strong>recipient_ids=</strong>(ids) 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


47
48
49</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 47</span>

<span class='def def kw'>def</span> <span class='recipient_ids= identifier id'>recipient_ids=</span><span class='lparen token'>(</span><span class='ids identifier id'>ids</span><span class='rparen token'>)</span>
  <span class='self self kw'>self</span><span class='dot token'>.</span><span class='recipients identifier id'>recipients</span> <span class='assign token'>=</span> <span class='ids identifier id'>ids</span><span class='dot token'>.</span><span class='split identifier id'>split</span><span class='lparen token'>(</span><span class='string val'>&quot;,&quot;</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='collect identifier id'>collect</span><span class='lbrace token'>{</span><span class='bitor op'>|</span><span class='id identifier id'>id</span><span class='bitor op'>|</span> <span class='User constant id'>User</span><span class='dot token'>.</span><span class='find_by_id identifier id'>find_by_id</span><span class='lparen token'>(</span><span class='id identifier id'>id</span><span class='rparen token'>)</span><span class='rbrace token'>}</span><span class='dot token'>.</span><span class='compact identifier id'>compact</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="sort_recipients-instance_method">
  
    - (<tt>Object</tt>) <strong>sort_recipients</strong> 
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


81
82
83
84
85
86</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/models/broadcast.rb', line 81</span>

<span class='def def kw'>def</span> <span class='sort_recipients identifier id'>sort_recipients</span>
  <span class='sms identifier id'>sms</span> <span class='assign token'>=</span> <span class='lbrack token'>[</span><span class='rbrack token'>]</span>
  <span class='email identifier id'>email</span> <span class='assign token'>=</span> <span class='lbrack token'>[</span><span class='rbrack token'>]</span>
  <span class='recipients identifier id'>recipients</span><span class='dot token'>.</span><span class='each identifier id'>each</span><span class='lbrace token'>{</span><span class='bitor op'>|</span><span class='r identifier id'>r</span><span class='bitor op'>|</span> <span class='r identifier id'>r</span><span class='dot token'>.</span><span class='can_get_sms? fid id'>can_get_sms?</span> <span class='integer val'>? </span><span class='sms identifier id'>sms</span> <span class='lshft op'>&lt;&lt;</span> <span class='r identifier id'>r</span> <span class='colon op'>:</span> <span class='email identifier id'>email</span> <span class='lshft op'>&lt;&lt;</span> <span class='r identifier id'>r</span><span class='rbrace token'>}</span>
  <span class='lbrack token'>[</span><span class='sms identifier id'>sms</span><span class='comma token'>,</span> <span class='email identifier id'>email</span><span class='rbrack token'>]</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Thu Dec  8 13:43:22 2011 by 
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.7.3 (ruby-1.8.7).
</div>

  </body>
</html>